#ifndef TRIGGER_H
#define TRIGGER_H

#include "command.h"
#include "log.h"
#include "serialportsync.h"

#include <QMutex>
#include <QObject>
#include <QRunnable>
#include <qthread.h>
#include "global.h"

class Trigger : public QThread
{
    Q_OBJECT
public:
    Trigger(QObject *parent = nullptr);
    void setBuzzing(bool bBuzzing);

signals:
    void signalInfo(Global::Cmd cmd, Global::Result result, QString info);

public slots:
    // void slotTimeout();

protected:
    void run() override;

private:
    bool init(QString& err);
    bool initGpio(int gpio, QString type);
    bool readGpio(int gpio);
    bool writeGpio(int gpio, int value);
    bool buzzing();

private:
    static const int    m_gpioStop = 130;
    static const int    m_gpioPowerOff = 135;
    static const int    m_gpioBuzzing = 131;
    int                 m_level;
    QAtomicInteger<bool>m_bBuzzing;
};

#endif // TRIGGER_H
